package com.itheima.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * Collection 遍历
 * 迭代器
 */
public class Test02 {

    public static void main(String[] args) {
        //创建集合对象
        Collection<String> collection = new ArrayList<>();//多态
        //添加元素
        collection.add("蔡徐坤");
        collection.add("吴亦凡");
        collection.add("黄子韬");
        collection.add("鹿晗");
        collection.add("蔡徐坤");
       //创建迭代器对象
        Iterator<String> iterator = collection.iterator();

        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }

      /*  System.out.println(iterator.next());
        System.out.println(iterator.next());
        System.out.println(iterator.next());
        System.out.println(iterator.next());
        System.out.println(iterator.next());*/
    }
}
